﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ERP.ERPSystem.ProductionSystem.Dto;
using ERP.Team.ProductionSystem;
using ERP.Common.Results;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Application.Dtos;

namespace ERP.ERPSystem.ProductionSystem
{
    //生产系统-生产管理-生产工单
    public interface IProductionWorkOrderMainServices : IApplicationService
    {
        /// <summary>
        /// 添加生产工单
        /// </summary>
        /// <param name="productionWorkOrderMainDto">工单信息</param>
        /// <returns>工单ID</returns>
        Task<int> AddProductionWorkOrder(ProductionWorkOrderDto productionWorkOrderMainDto);

        /// <summary>
        /// 获取生产工单列表
        /// </summary>
        /// <param name="workOrderCode">工单编号</param>
        /// <param name="workOrderName">工单名称</param>
        /// <param name="sourceOrder">来源订单</param>
        /// <param name="workOrderType">工单类型</param>
        /// <param name="productCode">产品编号</param>
        /// <param name="productName">产品名称</param>
        /// <param name="customerCode">客户编号</param>
        /// <param name="customerName">客户名称</param>
        /// <param name="demandDate">需求日期</param>
        /// <returns>工单列表</returns>
        Task<List<ProductionWorkOrderMain>> GetProductionWorkOrder(
            string workOrderCode = "",
            string workOrderName = "",
            string sourceOrder = "",
            string workOrderType = "",
            string productCode = "",
            string productName = "",
            string customerCode = "",
            string customerName = "",
            string demandDate = "");

        /// <summary>
        /// 分页查询生产工单
        /// </summary>
        /// <param name="skipCount">跳过记录数</param>
        /// <param name="maxResultCount">返回最大记录数</param>
        /// <returns></returns>
        Task<PagedResultDto<ProductionWorkOrderMain>> GetPagedProductionWorkOrder(int skipCount, int maxResultCount);

        /// <summary>
        /// 删除生产工单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task DeleteProductionWorkOrder(int id);

        /// <summary>
        /// 根据ID获取生产工单
        /// </summary>
        /// <param name="id">工单ID</param>
        /// <returns></returns>
        Task<ProductionWorkOrderMain> GetAsync(int id);

        /// <summary>
        /// 更新生产工单
        /// </summary>
        /// <param name="productionWorkOrderMainDto"></param>
        /// <returns></returns>
        Task<int> UpdateProductionWorkOrder(ProductionWorkOrderDto productionWorkOrderMainDto);

        /// <summary>
        /// 更新生产工单
        /// </summary>
        /// <param name="model">工单信息</param>
        /// <returns>是否成功</returns>
        Task<bool> UpdateWorkOrder(ProductionWorkOrderMain model);

        /// <summary>
        /// 获取甘特图数据
        /// </summary>
        /// <param name="queryDto">查询条件</param>
        /// <returns>甘特图数据列表</returns>
        Task<APIPaging<ProductionWorkOrderGanttDto>> GetGanttData(ProductionWorkOrderGanttQueryDto queryDto);

        /// <summary>
        /// 获取甘特图时间范围内的工单数据
        /// </summary>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>工单数据列表</returns>
        Task<List<ProductionWorkOrderGanttDto>> GetGanttDataByTimeRange(DateTime startTime, DateTime endTime);

        /// <summary>
        /// 更新工单生产进度
        /// </summary>
        /// <param name="workOrderId">工单ID</param>
        /// <param name="progressPercent">进度百分比</param>
        /// <param name="completedQuantity">已完成数量</param>
        /// <returns>更新结果</returns>
        Task<bool> UpdateProductionProgress(int workOrderId, decimal progressPercent, int completedQuantity);

        /// <summary>
        /// 更新工单生产状态
        /// </summary>
        /// <param name="workOrderId">工单ID</param>
        /// <param name="status">状态：0-未开始 1-进行中 2-已完成 3-暂停 4-异常</param>
        /// <returns>更新结果</returns>
        Task<bool> UpdateProductionStatus(int workOrderId, int status);

        // --------------------------------
        /// <summary>
        /// 查询工单
        /// </summary>
        /// <returns>返回数据</returns>
        Task<List<ProductionWorkOrderMain>> QueryWorkOrder();
    }
}
